const express = require("express");
const fs = require("fs");
const url = require("url");
const bodyParser = require("body-parser");
const handleHttp = require("./routers/handle-html.js");
const handleApi = require("./routers/handle-api.js");

//创建服务器
const server = express();

//路由router
//根据请求路径，将请求处理分给不同的模块完成

//http
server.use("/",handleHttp)

//处理ajax请求
server.use("/api",handleApi)

//处理静态资源文件
server.use("/static",express.static(__dirname+"/static"))

//启动服务器 开始监听
server.listen(8080,"localhost",(error)=>{
    if(!error){
        console.log("启动成功")
    }else{
        console.log("启动失败")
        console.log(error)
    }
})